package com.crm.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.util.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.google.gson.Gson;

public class test {
	
	public static String  getCompInfo(String copm){
		String result ="<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>";
		try{
			String str = "{\"__qymc\":\""+copm+"\"}";  
			Gson gson = new Gson();
	        String loginUrl = "http://jzsgl.coc.gov.cn/archi/ajaxpro/_1Archi.AjaxProxy.Changing_Person,_1Archi.AjaxProxy.ashx";  
	        HttpClient httpClient = new HttpClient();  
	        PostMethod post = new PostMethod(loginUrl);  
	        post.setRequestHeader("Accept","*/*");  
	        post.setRequestHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36");  
	        post.setRequestHeader("Accept-Language","zh-cn,zh;q=0.8");  
	        post.setRequestHeader("Accept-Encoding","gzip, deflate, sdch");  
	        post.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");  
	        post.setRequestHeader("Host","jzsgl.coc.gov.cn");  
	        post.setRequestHeader("X-AjaxPro-Method", "Get_NewEnterprise"); 
	        post.setRequestHeader("Cookie", "ASP.NET_SessionId=enaqhaayndjc0wocufnkbbk1; jzszxja=898E11E86D16DE729B2B48B4CE65EB5ECB4D27D10AB24231BA8DD13147FD0F303ED8323C1B2A08BDFEC7794D883AB9D3CFF81DCD0E9D4FBDAED01B87429D02A57DC99F39D0A014B24262D69CD64ACF6C78128D7B8F441A5AC4BE4541E288585AFA0269BAA18039312D04D85E5FD78DE25861064834E2B42A36CE4D41C45DBF6F8FAD14E5799830ECBBEE3D22E1FA78257EBA9B9EA78C7BBEA7FA653B0E6BD43CD97933A23C9F5FD29E3A8232D24BE7128D64E2B177474216FE7141794D87B90E021D141875E48830EE8FD821C93587CAD3404DC7EC090715D125FFCBDF6488117A493154B0ECEE2CC4AF16AB0F4DBE139907BD8D7626880926452B5EAA1DB8E30F598E608A7FDC7D2A7F8A12907FB01B437DC57E855A9550795BDB519B5DFF794A8862D926CF035BCA9CB8667B280177986C06749D86AFED43E1895B5115401761272BF38C915D91EE7006B2C5A9A034E59F917D6C3CF1F2C6A8128DEC53087C29DF70BA3F40483FA3F6CDCDF5B22D045C0636AB0FBCD66CB00F90CA26882B025B60237BF633B63BDCC7B45BEF43B2F19064027993BE9F33FFD330DCD70E91CA7EA3DF78AAB6CCE463012F6128C1D9CB93C77B2DD08BBDA43A3617E30BABDF746D8DD1E12B00D09EB3E8E5917C8CE00D1C0A9C2E26A012664E8B4522BDB32CE84A1E83B4D40E7BB96C0572AB506AEC49; Hm_lvt_71d250810c675a2d991b58dcb94e6801=1499066831; Hm_lpvt_71d250810c675a2d991b58dcb94e6801=1499067705"); 
	        post.setRequestHeader("Connection","keep-alive");  
	        post.setRequestHeader("Referer","http://jzsgl.coc.gov.cn/archi/PortalChanging/ChangingNewEditor.aspx");  
	        RequestEntity entity = new StringRequestEntity(str, "text/html", "utf-8");  
	        post.setRequestEntity(entity);  
	        httpClient.executeMethod(post);  
	        String html = post.getResponseBodyAsString();  
	        Map<String, Object> map4 = new HashMap<String, Object>();
	        map4 = gson.fromJson(html, map4.getClass());
	        System.out.println(html); 
	        //{"value":null}
	        //{"value":{"_qybm":"e258e7a8-e066-4aee-96c8-018b82332f0c","_qymc":"中信建筑设计研究总院有限公司","_qyxz":"国有企业","_gszcd":"湖北省武汉市","_fddbr":"郭粤梅","_txdz":"武汉市江岸区四唯路8号","_yzbm":"430014","_lxr":"盛瓅","_lxdh":"027-82739271","_qylx":"设计","_qyzzlb":"建筑","_zzdj":"甲级","_zzzsbh":"A142006013","_gszcsf":"湖北省","_sjbm":"420000"}}

	       Map<String,String> mapresult = (Map)map4.get("value");
	       if(mapresult!=null){
	    	   //<td>联系人</td><td>联系电话</td><td>资质类别</td><td>资质等级</td><td>地址</td>
	    	   result ="<td>"+mapresult.get("_lxr")+"</td><td>"+mapresult.get("_lxdh")+"</td><td>"+mapresult.get("_qyzzlb")+"</td><td>"+mapresult.get("_zzdj")+"</td><td>"+mapresult.get("_txdz")+"</td>";
	    	   System.out.println(mapresult.get("_qymc"));
	    	   
	       }
		   
		}catch(Exception e){
			
		}
		
		return result;
	}
	
	 
	
	
 public static void mainsss(String[] args) {
	 
	 try{
		/* String sssss ="序号	企业名称	企业资质	所在地区	联系人	联系方式	最后跟进时间	操作 "+
				 "1	测试卷哦	暂无资质情况		cc	123	2017-05-10  13888888888	查看  获取  跟进  回收   3	vgsbdhbdgbd  66796106/18013753080	暂无资18948354468质情况15955155626/15150192858				2017-04-24	查看  获取  跟进  回收 4	vgsdgdfrhbtdrghntr	暂无资质情况			"
				 + "	2017-04-24	查看  获取  跟进  回收 5 051257510602	cccdddsssweeweew "+
				 "本文转自有宠网：http://192.168.1.120:8080/customer/entman/ty1_st4";
		 String sss=  hidPhone(sssss);
		 
		 String fd="051257510602";
		 String reg="(?:(\\(\\+?86\\))(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)|(?:(86-?)?(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)";  
	       System.out.println(Pattern.matches(reg, fd)); 
		 
		 
		 
		 
		 
		 
   System.out.println(sss);*/
		 
		
		 
		    
		 
		// Document doc2 = Jsoup.connect("http://jzsgl.coc.gov.cn/archi/ajaxpro/_1Archi.AjaxProxy.Changing_Person,_1Archi.AjaxProxy.ashx").header("param","{\"__qymc\":\"湖北立方建设工程有限公司\"}").header("Content-Type", "text/plain; charset=UTF-8").header("X-AjaxPro-Method", "Get_NewEnterprise").header("Accept", "*/*").header("Host", "jzsgl.coc.gov.cn").header("Cookie", "ASP.NET_SessionId=enaqhaayndjc0wocufnkbbk1; jzszxja=898E11E86D16DE729B2B48B4CE65EB5ECB4D27D10AB24231BA8DD13147FD0F303ED8323C1B2A08BDFEC7794D883AB9D3CFF81DCD0E9D4FBDAED01B87429D02A57DC99F39D0A014B24262D69CD64ACF6C78128D7B8F441A5AC4BE4541E288585AFA0269BAA18039312D04D85E5FD78DE25861064834E2B42A36CE4D41C45DBF6F8FAD14E5799830ECBBEE3D22E1FA78257EBA9B9EA78C7BBEA7FA653B0E6BD43CD97933A23C9F5FD29E3A8232D24BE7128D64E2B177474216FE7141794D87B90E021D141875E48830EE8FD821C93587CAD3404DC7EC090715D125FFCBDF6488117A493154B0ECEE2CC4AF16AB0F4DBE139907BD8D7626880926452B5EAA1DB8E30F598E608A7FDC7D2A7F8A12907FB01B437DC57E855A9550795BDB519B5DFF794A8862D926CF035BCA9CB8667B280177986C06749D86AFED43E1895B5115401761272BF38C915D91EE7006B2C5A9A034E59F917D6C3CF1F2C6A8128DEC53087C29DF70BA3F40483FA3F6CDCDF5B22D045C0636AB0FBCD66CB00F90CA26882B025B60237BF633B63BDCC7B45BEF43B2F19064027993BE9F33FFD330DCD70E91CA7EA3DF78AAB6CCE463012F6128C1D9CB93C77B2DD08BBDA43A3617E30BABDF746D8DD1E12B00D09EB3E8E5917C8CE00D1C0A9C2E26A012664E8B4522BDB32CE84A1E83B4D40E7BB96C0572AB506AEC49; Hm_lvt_71d250810c675a2d991b58dcb94e6801=1499066831; Hm_lpvt_71d250810c675a2d991b58dcb94e6801=1499067705").header("Referer", "http://jzsgl.coc.gov.cn/archi/PortalChanging/ChangingNewEditor.aspx").timeout(62000).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").post();
		//	System.out.println(doc2);
		 
		 
		 
		 
		  StringBuffer  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>企业名称</td><td>联系人</td><td>联系电话</td><td>资质类别</td><td>资质等级</td><td>地址</td><td>当前人数</td><td>初始注册</td><td>变更注册</td></tr>");
		  Gson gson = new Gson();
		 List<String[]>  list = new ArrayList();
		 for(int j=1;j<10;j++){   
			 try{
				 //020102   010102
				 Document doc = Jsoup.connect("http://jzsgl.coc.gov.cn/archisearch/AjaxAction/DataServices.ashx").data("param","{\"Sjbm\":\"510000\",\"Qymc\":\"\",\"PageNo\":"+j+"}").data("action","020102").header("X-Requested-With", "XMLHttpRequest").header("Accept", "application/json, text/javascript, */*; q=0.01").header("Host", "jzsgl.coc.gov.cn").header("Cookie", "Hm_lvt_cfe2a1fc66d26c96eb2192ef8d25c599=1499064061,1499066851; Hm_lpvt_cfe2a1fc66d26c96eb2192ef8d25c599=1499066859; Hm_lvt_71d250810c675a2d991b58dcb94e6801=1499066831; Hm_lpvt_71d250810c675a2d991b58dcb94e6801=149906683").header("X-Referer", "http://jzsgl.coc.gov.cn/archisearch/cxejjzs/qylist.aspx?sjbm=510000").header("Referer", "http://jzsgl.coc.gov.cn/archisearch/cxejjzs/qylist.aspx?sjbm=510000").timeout(62000).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").ignoreContentType(true).post();
				System.out.println(j);
			
				 Map<String, Object> map = new HashMap<String, Object>();
				 map = gson.fromJson(doc.select("body").html().replace("&quot;", "'"), map.getClass());
				 
				 System.out.println(map);
				Map<String,Map<String,Object>> mp = (Map)map.get("AppendData");
				List<Map> mpt =  (ArrayList)mp.get("Data");
				
				for(Map<String,Object> mapsss:mpt){
					try{
						String tr ="<tr><td>"+mapsss.get("qymc")+"</td>"+getCompInfo((String)mapsss.get("qymc"))+"<td>"+mapsss.get("count00")+"</td><td>"+mapsss.get("count01")+"</td><td>"+mapsss.get("count02")+"</td></tr>";
						table.append(tr);
					}catch(Exception eee){
						
					}
					
					
				}
			 }catch(Exception e){
				 
			 }
		
			//Map<String,Object> mapsss= (Map)mpt.get(0);
			
			 //JSONArray   js = JSONArray.parseArray(doc.select("body").html().replace("&quot;", "'"));
			// System.out.println(js);
			 
			 /*Elements  el = doc.select(".icheck");
			 for(Element e:el){
				String[]  ss= e.attr("value").replace("{", "").replace("}", "").replace("\"", "").replace("apt_code:", "").replace("apt_scope:", "").split(",");
				list.add(ss);
			 }*/
		 }
		
		 table.append("</table></body></html>");
			
		    
         PrintStream printStream = new PrintStream(new FileOutputStream("d://reporttab.html")); 
         printStream.println(table.toString()); 
         System.out.println("已成功输出");
		 System.out.println(list);
		 
		/*   StringBuffer  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>序号</td><td>信用代码</td><td>公司名称</td><td>法定代表</td><td>注册地</td></tr>");
		 for(int i=1;i<31;i++){
			 
			 try{
				 Elements ss= url(i+"");
				 table.append(ss.html()); 
			 }catch(Exception e){
				 break ;
			 }
		
			 try {
                  //sleep()方法导致了程序暂停执行指定的时间，让出cpu该其他线程，
              //但是他的监控状态依然保持者，当指定的时间到了又会自动恢复运行状态。
                  //在调用sleep()方法的过程中，线程不会释放对象锁。
 		                   Thread.sleep(5000);
 		       } catch (Exception e) {
 	                    e.printStackTrace();
 		  }
		 }
		 
		    table.append("</table></body></html>");
		
		    
            PrintStream printStream = new PrintStream(new FileOutputStream("d://reporttab.html")); 
            printStream.println(table.toString()); 
            System.out.println("已成功输出");
		 */
		}catch(Exception e){
			e.printStackTrace();
		}
	 
	 
	 
}
 
 public static void main(String[] args) {
	 
	   StringBuffer  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>公司名称</td><td>检索内容</td><td>检索内容</td><td>检索内容</td><td>检索内容</td><td>检索内容</td><td>检索内容</td><td>检索内容</td><td>检索内容</td></tr>");
       
	  try {
          String encoding="UTF-8";
          File file=new File("d:\\td.txt");
          if(file.isFile() && file.exists()){ //判断文件是否存在
              InputStreamReader read = new InputStreamReader(
              new FileInputStream(file),encoding);//考虑到编码格式
              BufferedReader bufferedReader = new BufferedReader(read);
              String lineTxt = null;
              int i =0;
              while((lineTxt = bufferedReader.readLine()) != null){
                  System.out.println(lineTxt);
             	 try{
             		 
             		String dt[] = lineTxt.split("，");
             		
             		  
             		 Element sss =  urlbyidcard(dt[1]);
             		 if(sss!=null){
             			String td =  sss.select("tr").html(); 
             			table.append("<tr><td>"+dt[0]+"</td><td>"+dt[1]+"</td><td>"+dt[2]+"</td>"+td+"</tr>");
             			System.out.println(td);
             		 } 	
             		}catch(Exception e){
             			e.printStackTrace();
             		}
             	 /*if(i>10){
             		 break;
             	 }*/
           	  try {
                  
  		                   Thread.sleep(20000);
	  		       } catch (Exception e) {
	  	                    e.printStackTrace();
	  		  }
             	 
             	 i++;
              }
              table.append("</table></body></html>");
              read.close();
              
              
               
              PrintStream printStream = new PrintStream(new FileOutputStream("d://report.html")); 
              printStream.println(table.toString()); 
              System.out.println("已成功输出");
  }else{
      System.out.println("找不到指定的文件");
  }
  } catch (Exception e) {
      System.out.println("读取文件内容出错");
      e.printStackTrace();
  }
	 
	 
}
 
	 
 public static Element  urlbyidcard(String idcard){
	 try{
			Document doc = Jsoup.connect("http://jzsc.mohurd.gov.cn/dataservice/query/staff/list").timeout(62000).data("ry_type","").data("ry_reg_type","").data("ry_name","").data("reg_seal_code","").data("ry_cardno","").data("ry_qymc","").data("complexname",idcard).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").post();
			Element tr = doc.select(".cursorDefault  tr").get(0);
			int  tds = tr.select("td").size();
			if(tds<2){
				return null;
			}else{
				return tr;
			}
	 }catch(Exception e){
		return null;
	 }
	  
}  
	 
 
 public static String hidPhone(String string) {
     Pattern pattern = Pattern.compile("(?<!\\d)(?:(?:1[34578]\\d{9})|(?:861[34578]\\d{9})|(?:(\\(\\+?86\\))(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)|(?:(86-?)?(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?))(?!\\d)");
     Matcher matcher = pattern.matcher(string);
     StringBuffer bf = new StringBuffer(64);
     int i = 0;
     while (matcher.find()) {
//        bf.append(matcher.group()).append(",");
//         System.out.println(matcher.group());
         string = string.replace(matcher.group(), matcher.group().substring(0,3)+"****"+ matcher.group().substring(matcher.group().length()-3,matcher.group().length()));
         i++;
     }
     
//		int len = bf.length();
//		if (len > 0) {
//			bf.deleteCharAt(len - 1);
//		}
//		System.out.println(bf.toString());
	
     return string;
 }
 
 public static Elements  url(String pg){
	 try{
			Document doc = Jsoup.connect("http://jzsc.mohurd.gov.cn/dataservice/query/comp/list").timeout(62000).data("apt_code","D101C").data("apt_scope","建筑工程施工总承包三级").data("qy_gljg","").data("$pg",pg).data("qy_type","").data("$reload","0").data("qy_region","420000").data("apt_certno","").data("$pgsz","15").data("qy_name","").data("qy_code","").data("qy_reg_addr","湖北省").data("$total","3078").data("qy_fr_name","").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").post();
			//Element  el = doc.select(".cursorDefault  tr").get(0);
			return doc.select(".cursorDefault");
	 }catch(Exception e){
		return null;
	 }
	 
	 
 } 
 public static String  url2(String href ,String cp){
	 try{
		 Document doc1 = Jsoup.connect("http://jzsc.mohurd.gov.cn"+href).data("complexname",cp).timeout(62000).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
			String address = doc1.select(".datas_table tbody tr").get(3).select("td").get(0).text();
			return address;
	 }catch(Exception e){
		return url2(href,cp);
	 } 
 } 
 
 public static Elements  url3(String href ,String cp){
	 try{
		 Document doc2 = Jsoup.connect("http://jzsc.mohurd.gov.cn"+href.replace("compDetail", "caDetailList")).timeout(62000).data("complexname",cp).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
			 
		  Elements  trs = doc2.select(".cursorDefault tr");
		    trs.get(0);
			return trs;
	 }catch(Exception e){
		return url3(href,cp);
	 } 
 } 
 
 
 
 public static void readTxtFileTwo(String filePath){
     try {
             String encoding="GBK";
             File file=new File(filePath);
             if(file.isFile() && file.exists()){ //判断文件是否存在
                 InputStreamReader read = new InputStreamReader(
                 new FileInputStream(file),encoding);//考虑到编码格式
                 BufferedReader bufferedReader = new BufferedReader(read);
                 String lineTxt = null;
                 int i =0;
                 StringBuffer  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>公司名称</td><td>资质</td><td>地址</td></tr>");
                 while((lineTxt = bufferedReader.readLine()) != null){
                     System.out.println(i+"---"+lineTxt);
                	 try{
                		 
     
                	//		Document doc = Jsoup.connect("http://59.175.169.110/Ewmwz/QyManage/QyzzSearch.aspx?ssl=107&__EVENTTARGET=lbtnGo&__EVENTARGUMENT=").data("hSsl","107").data("txtPageIndex","7").data("__EVENTVALIDATION","/wEWCwK/1PzdCQK4s/fhCgLyxsSSBAKln/PuCgKSq+DOBgLtgtDiCgLk9PbGCgLvwfqHDwKT7byBDAKl+aafDQLznLb/CI2nZuTv9CMX1LBUrH6Ogn9RvLjYxdRzF34fVTwKXySa").data("__VIEWSTATE","/wEPDwULLTE0MDIxNzQ2NTIPZBYC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.0; BIDUBrowser 2.x)").post();
                			String cp =lineTxt;
                			//String sss = URLEncoder.encode(cp+" 电话|手机|联系方式");
                			//Document doc = Jsoup.connect("http://jzsc.mohurd.gov.cn/dataservice/query/comp/list").timeout(62000).data("complexname",cp).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").post();
                			Elements  td = url("");//doc.select(".cursorDefault  tr").get(0);
                			//Elements td = el.select(".primary");
                			if(td!=null&&StringUtils.isNotEmpty(td.text())){
                				 if(td.text().equals(cp)){
                					//  table.append("<tr><td>"+cp+"</td><td>"+contents+"</td</tr>");
                					String href =  td.select("a").attr("href");
                					// Document doc1 = Jsoup.connect("http://jzsc.mohurd.gov.cn"+href).data("complexname",cp).timeout(62000).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
                					String address =url2(href,cp); //doc1.select(".datas_table tbody tr").get(3).select("td").get(0).text();
                					 //System.out.println(address);
                					 
                					// Document doc2 = Jsoup.connect("http://jzsc.mohurd.gov.cn"+href.replace("compDetail", "caDetailList")).timeout(62000).data("complexname",cp).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
                 					 
                					  Elements  trs = url3(href,cp);// doc2.select(".cursorDefault tr");
                					  String zzmc = "";
                					  String zzrq ="";
                					   if(trs.size()>1){
                						  int y =0;
                						  for(Element tr:trs){
                							  Elements tds =  tr.select("td");
                							  if(tds.size()>2){
                								
                								  
                								 /* for(Element tdobj:tds){
                									 String  zzmchead = tdobj.attr("data-header");
                									 if(zzmchead.equals("资质名称")){
                										 
                									 }
                								  }*/
                								   zzrq = tds.get(4).text();//日期
                								   zzmc +="["+zzrq+"]" +tds.get(3).text()+"<br>";//名称
                								  
                							  }else{
                								    zzmc += tds.get(1).text()+"<br>";
                							  }
                							 // y++;
                						  }
                					 }else{
                						  Elements tds =  trs.get(0).select("td");
                						   zzrq = tds.get(4).text();//日期
                						   zzmc += "["+zzrq+"]" +tds.get(3).text();//名称
        								 
                					  } 
                					 
                					  table.append("<tr><td>"+cp+"</td><td>"+zzmc+"</td><td>"+address+"</td></tr>");
                					  //<tr><td>公司名称</td><td>资质</td><td>发证日期</td><td>地址</td></tr>
                					  
                    				 //System.out.println("----"+);
                				 }
                				
                				
                			}
                			
                			  try {
     		                     //sleep()方法导致了程序暂停执行指定的时间，让出cpu该其他线程，
     		                 //但是他的监控状态依然保持者，当指定的时间到了又会自动恢复运行状态。
     		                     //在调用sleep()方法的过程中，线程不会释放对象锁。
			     		                   Thread.sleep(5000);
			     		       } catch (Exception e) {
			     	                    e.printStackTrace();
			     		  }
                			
                			/* if(contents.length()>0){
                				  table.append("<tr><td>"+cp+"</td><td>"+contents+"</td</tr>");
                				 
                			 }*/
                			//System.out.println();
                			
                		}catch(Exception e){
                			e.printStackTrace();
                		}
                	  if(i>500){
                	   // break;
                		  try{
                			  i=0;
                      		Date d =  new Date();
                      		
                      		   table.append("</table></body></html>");
                      		  PrintStream printStream = new PrintStream(new FileOutputStream("d://report"+d.getTime()+".html")); 
                                printStream.println(table.toString()); 
                                System.out.println("已成功输出");
                      		  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>公司名称</td><td>资质</td><td>地址</td></tr>");
                      		 
                		  }catch(Exception ec){
                			  ec.printStackTrace();
                		  }
                		
                		 
                	 }  
                	 i++;
                 }
                 table.append("</table></body></html>");
                 read.close();
                 
              try{
            	  Date d =  new Date();
                 PrintStream printStream = new PrintStream(new FileOutputStream("d://report"+d.getTime()+".html")); 
                 printStream.println(table.toString()); 
                 System.out.println("已成功输出");
            	 
       		  }catch(Exception ec){
       			  ec.printStackTrace();
       		  }
     }else{
         System.out.println("找不到指定的文件");
     }
     } catch (Exception e) {
         System.out.println("读取文件内容出错");
         e.printStackTrace();
     }
     
  
 }
 
 
 public static void readTxtFile(String filePath){
     try {
             String encoding="GBK";
             File file=new File(filePath);
             if(file.isFile() && file.exists()){ //判断文件是否存在
                 InputStreamReader read = new InputStreamReader(
                 new FileInputStream(file),encoding);//考虑到编码格式
                 BufferedReader bufferedReader = new BufferedReader(read);
                 String lineTxt = null;
                 int i =0;
                 StringBuffer  table = new StringBuffer("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body><table border=1><tr><td>公司名称</td><td>检索内容</td</tr>");
                 while((lineTxt = bufferedReader.readLine()) != null){
                     System.out.println(lineTxt);
                	 try{
                		 
     
                	//		Document doc = Jsoup.connect("http://59.175.169.110/Ewmwz/QyManage/QyzzSearch.aspx?ssl=107&__EVENTTARGET=lbtnGo&__EVENTARGUMENT=").data("hSsl","107").data("txtPageIndex","7").data("__EVENTVALIDATION","/wEWCwK/1PzdCQK4s/fhCgLyxsSSBAKln/PuCgKSq+DOBgLtgtDiCgLk9PbGCgLvwfqHDwKT7byBDAKl+aafDQLznLb/CI2nZuTv9CMX1LBUrH6Ogn9RvLjYxdRzF34fVTwKXySa").data("__VIEWSTATE","/wEPDwULLTE0MDIxNzQ2NTIPZBYCAgMPZBYQAgMPFgIeCWlubmVyaHRtbAUh5bu6562R5Lia5LyB5Lia6LWE6LSo5L+h5oGv5p+l6K+iZAILDxYCHwAFaeazqO+8muacrOafpeivouS7hemZkOWcqOaWsOeJiOihjOaUv+WuoeaJueezu+e7n+WKnueQhui/h+W7uuetkeS4muS8geS4mui1hOi0qOihjOaUv+iuuOWPr+S6i+mhueeahOS8geS4mmQCDQ8WAh4LXyFJdGVtQ291bnQCFBYoZg9kFgJmDxUKATEGMTg3MzQzBTY1MTU0AzEwNyTmuZbljJfkuK3ng4Hlu7rorr7lt6XnqIvmnInpmZDlhazlj7gSOTE0MjExMjU1NzM3MjE0MDMyCemCteWwj+agixXlu7rnrZHkuJrkvIHkuJrotYT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wOGQCEg9kFgJmDxUKAjE5BjE5MDQ2MgU2OTAwMQMxMDck5rmW5YyX6ZSm5Y6m5bu66K6+5pyJ6ZmQ6LSj5Lu75YWs5Y+4EjkxNDIwNjAwNzQxNzczNTEwWQnog6HmtKrlkK8V5bu6562R5Lia5LyB5Lia6LWE6LSoCkQxNDIwOTg4NjEKMjAxNi0wOC0yOWQCEw9kFgJmDxUKAjIwBjE5MDk4NgU2MjIwOQMxMDck5rmW5YyX5ZCM55Ge5bu66K6+5Y+R5bGV5pyJ6ZmQ5YWs5Y+4EjkxNDIwMTA2MDkyMDA2ODQ3NAnnjovlhajli4cV5bu6562R5Lia5LyB5Lia6LWE6LSoCkQxNDIwOTkwNDkKMjAxNi0wOC0yOWQCDw8PFgIeBFRleHQFATRkZAIRDw8WAh8CBQM4ODhkZAITDw8WAh8CBQUxNzc0NGRkAhcPDxYCHgdFbmFibGVkZ2RkAhkPDxYCHwNnZGRk8E53rp2C/lW2FRxmxylNzeV/Y/HiNYZ2hIDEZsfSp58=").timeout(62000).header("Origin", "http://59.175.169.110").header("Referer", "http://59.175.169.110/Ewmwz/QyManage/QyzzSearch.aspx?ssl=107").userAgent("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; BIDUBrowser 2.x)").post();
                			String cp =lineTxt;
                			String sss = URLEncoder.encode(cp+" 电话|手机|联系方式");
                			Document doc = Jsoup.connect("https://www.baidu.com/s?wd="+sss+"&rsv_spt=1&rsv_iqid=0x9b82a590000057ef&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&rqlang=cn&tn=baiduhome_pg&rsv_enter=0&inputT=849&rsv_t=6682eK25zVrc6zOj%2FYjrgI6AgKETHWJu8wOTSEbuq%2Fc0oXfI30Vx%2BubfRnA3lh18c4kW&oq=%25E6%25B9%2596%25E5%258C%2597%25E9%2594%25A6%25E5%258E%25A6%25E5%25BB%25BA%25E8%25AE%25BE%25E6%259C%2589%25E9%2599%2590%25E8%25B4%25A3%25E4%25BB%25BB%25E5%2585%25AC%25E5%258F%25B8%2520%25E7%2594%25B5%25E8%25AF%259D%257C%25E6%2589%258B%25E6%259C%25BA%257C%25E8%2581%2594%25E7%25B3%25BB%25E6%2596%25B9%25E5%25BC%258F&rsv_pq=93112c3d00007901&rsv_sug3=46&rsv_n=2&rsv_sug2=0&rsv_sug4=849").userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36").get();
                			 Elements  els = doc.select(".result");
                			 String contents ="";
                			 for(Element e:els){
                				String title =  e.select("h3").text();
                				String content =  e.select(".c-abstract").text();
                				//System.out.println(title+"----"+isphone(content)+"--"+isName(cp,content));
                			 
                				  if(isphone(content) && isName(cp,content)){
                					  contents += content+"</br>";
                					//System.out.println(content);
                				  } 
                			 }
                			 if(contents.length()>0){
                				  table.append("<tr><td>"+cp+"</td><td>"+contents+"</td</tr>");
                				 
                			 }
                			//System.out.println();
                			
                		}catch(Exception e){
                			e.printStackTrace();
                		}
                	 /*if(i>10){
                		 break;
                	 }*/
                	 i++;
                 }
                 table.append("</table></body></html>");
                 read.close();
                 
                 
                  
                 PrintStream printStream = new PrintStream(new FileOutputStream("d://report.html")); 
                 printStream.println(table.toString()); 
                 System.out.println("已成功输出");
     }else{
         System.out.println("找不到指定的文件");
     }
     } catch (Exception e) {
         System.out.println("读取文件内容出错");
         e.printStackTrace();
     }
     
  
 }
 
 public static boolean isphone(String str)  {  
     String regExp = "^((?!(\\d{7})).)*$";  // "^((?!(1[3|4|5|8|7][0-9]\\d{8})).)*$"
     Pattern p = Pattern.compile(regExp);  
     Matcher m = p.matcher(str);  
     return !m.matches();  
 }  
 
 public static boolean isName(String ti,String str)  {  
     String regExp = "^((?!"+ti+").)*$";  // "?1[3|4|5|8][0-9]\\d{8}*+$";  
     Pattern p = Pattern.compile(regExp);  
     Matcher m = p.matcher(str);  
     return !m.matches();  
 }  
 
 
 
 
 
 
 
 
}
